package com.amado.course36ByteStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
 *  字节流读取文件信息
 * @author Administrator
 *
 */
public class S02FileInputStreamTest2 {
	public static void main(String[] args) throws IOException {
		File file = new File("D:\\Hello.java");
		//字节流输入对象，输入流
		FileInputStream inputStream = null;
		byte[] byteArray = new byte[20];
		try {
			inputStream = new FileInputStream(file);
			//读取一个字节
			int intByte = inputStream.read();
			System.out.println((char)intByte);
			//读取一个数组[20]
			inputStream.read(byteArray);
			System.out.println(new String(byteArray));
			//跳过10个字节
			inputStream.skip(10);
			//读取一个数组[20]
			inputStream.read(byteArray);
			//把字节转换为字符串类型
			System.out.println(new String(byteArray));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			inputStream.close();
		}
	}
}
